package com.devilvan.customPartition;

import lombok.Data;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

@Data
public class FlowEntity implements WritableComparable<FlowEntity> {
    private Long reportTime;
    private String msiSdn;
    private String apMac;
    private String acMac;
    private String host;
    private String siteType;
    private Long upPackNum;
    private Long upPayLoad;
    private Long downPackNum;
    private Long downPayLoad;
    private String httpStatus;

    @Override
    public int compareTo(FlowEntity o) {
        // 根据downPackNum进行升序排序，如果相同则再根据upPayLoad进行降序排序
//        int flag = this.downPayLoad.compareTo(o.downPackNum);
//        if (flag == 0) {
//            flag = -this.upPayLoad.compareTo(o.upPayLoad);
//        }
//        return flag;
        return reportTime.compareTo(o.reportTime);
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(reportTime);
        out.writeUTF(msiSdn);
        out.writeUTF(apMac);
        out.writeUTF(acMac);
        out.writeUTF(host);
        out.writeUTF(siteType);
        out.writeLong(upPackNum);
        out.writeLong(downPackNum);
        out.writeLong(upPayLoad);
        out.writeLong(downPayLoad);
        out.writeUTF(httpStatus);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.reportTime = in.readLong();
        this.msiSdn = in.readUTF();
        this.apMac = in.readUTF();
        this.acMac = in.readUTF();
        this.host = in.readUTF();
        this.siteType = in.readUTF();
        this.upPackNum = in.readLong();
        this.downPackNum = in.readLong();
        this.upPayLoad = in.readLong();
        this.downPayLoad = in.readLong();
        this.httpStatus = in.readUTF();
    }
}
